package zm.irc.threads;

import org.apache.log4j.Logger;

public abstract class IrcThread implements Runnable{
    private static final Logger log = Logger.getLogger(IrcThread.class);
    private volatile boolean shouldStop;


    @Override
    public void run() {
        this.beforeLoop();
        this.shouldStop = false;
        while(!this.shouldStop){
            try{
                this.before();
                this.doRun();
                this.after();
            }catch(Exception e){
                log.error("Thread error!",e);
            }
        }
        
    }

    public void stopIrcThread(){
        this.shouldStop = true;
    }

    protected void beforeLoop(){
        //Do nothing
    }

    protected void before() throws Exception{
        //Do nothing
    }

    protected  abstract void doRun();

    protected  void after() throws Exception{
        //Do nothing
    }
    
    
}
